/**
 * 
 */
package ch.janotta.slawo.ultraquest.utilities;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author slawo
 * 
 */
public final class TestSettings {
  private static final Logger LOGGER = LoggerFactory.getLogger(TestSettings.class);

  private static final String TEST_PREFERENCES_FILE_NAME = "test.preferences";

  private static Properties testPreferences;

  public static String getSetting(String key) {
    if (testPreferences == null) {
      loadPreferences();
    }
    return testPreferences.getProperty(key);
  }

  private static void loadPreferences() {
    if (testPreferences == null) {
      testPreferences = new Properties();
      Path testSettingsPath = Paths.get("src", "test", "resources", TEST_PREFERENCES_FILE_NAME);
      try {
        testPreferences.load(Files.newInputStream(testSettingsPath));
      } catch (IOException e) {
        LOGGER.error("Error encountered while loading test settings from file " + TEST_PREFERENCES_FILE_NAME
            + ". Path used was " + testSettingsPath, e);
      }
    }
  }
}
